/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tr.com.oyunus.server.impl;

import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import org.jboss.netty.handler.codec.http.HttpChunkAggregator;
import org.jboss.netty.handler.codec.http.HttpContentCompressor;
import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
import org.jboss.netty.handler.codec.string.StringDecoder;
import org.jboss.netty.handler.codec.string.StringEncoder;
import org.jboss.netty.handler.stream.ChunkedWriteHandler;
import org.jboss.netty.util.CharsetUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author ginnun
 */
@Component
public class SimpleOyunusPipelineFactory implements ChannelPipelineFactory {
    @Autowired
    SimpleChannelUpstreamHandler simpleOyunusServerRequestHandler      ;

    @Override
    public ChannelPipeline getPipeline() throws Exception {
        ChannelPipeline pipeline = Channels.pipeline();
        // Create a default pipeline implementation.



        pipeline.addLast("decoder", new HttpRequestDecoder());
        pipeline.addLast("stringDecoder", new StringDecoder(CharsetUtil.UTF_8));
        pipeline.addLast("aggregator", new HttpChunkAggregator(65536));
        pipeline.addLast("deflater", new HttpContentCompressor());
        pipeline.addLast("encoder", new HttpResponseEncoder());
       // pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
        // Encoder
        pipeline.addLast("stringEncoder", new StringEncoder(CharsetUtil.UTF_8));

        pipeline.addLast("handler", simpleOyunusServerRequestHandler);

        return pipeline;
    }
}
